package demo4;

class Money implements Cloneable
{
    public double money=12.25;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable
{
    public String name;
    public Money m=new Money();

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student student=(Student) super.clone();
        student.m=(Money)this.m.clone();
        return student;
        //return super.clone();
    }
}
public class test {
    public static void main(String[] args) throws CloneNotSupportedException{
        Student student=new Student();
        Student student1=(Student) student.clone();
        System.out.println(student.m.money);
        System.out.println(student1.m.money);
        System.out.println("=============");
        student1.m.money=99;
        System.out.println(student.m.money);
        System.out.println(student1.m.money);
    }
    public static void main1(String[] args) throws CloneNotSupportedException {
        Student student=new Student();
        student.name="123";
        Student student1=(Student) student.clone();
        System.out.println(student);
        System.out.println(student1);

    }
}



